﻿@{
    ViewBag.Title = "ImportGoods";
}

@section scripts
{    
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script> 
}

<div class="mini-splitter" style="width:100%;height:100%;">
    <div size="270" showcollapseButton="true">
        <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
            <table>
                <tr>
                    <td width ="80px" align="right">分类名称: </td>
                    <td width ="110px" ><input class="mini-textbox" id ="FSearchKey" width ="110px" name = "FSearchKey" onkeypress="setkeyPressCls()"/></td>
                    <td width ="80px" align="center">
                        <a class="mini-button" iconCls="icon-search" onclick="setkeyPressCls" plain="true">查询</a>
                    </td>
                </tr>
            </table>
        </div>
        <div class="mini-fit" >
            <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                    borderStyle="border:1;" url="../Goods/GetSysClassList"
                    allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"  
                    sortMode="client">
                <div property="columns">
                    <div type="checkboxcolumn" field="Flag" trueValue="1" falseValue="0" width="40" ></div>
                    <div type="indexcolumn" width="40" headerAlign="center" >序号</div>                    
                    <div field="FClassName" name="FClassName" width="150" headeralign="center" allowsort="true">分类名称</div>
                </div>
            </div>
        </div>
    </div>

    <div showCollapseButton="true">
        <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
            <table style="width:100%;">
                <tr>
                    <td style="width:350px;">
                        <a class="mini-button" id="fresh" name="fresh" iconCls="icon-search" onclick="search" plain="true">刷新</a>
                         <span class="separator"></span>
                        <a class="mini-button" id="save" name="save" iconCls="icon-save" onclick="save" plain="true">引入</a>
                        <span class="separator"></span>
                        <a class="mini-menubutton" plain="true" iconCls="icon-expand" menu="#popupMenu">查看</a>
                         <span class="separator"></span>
                        <a class="mini-button" id="close" name="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                    </td>
                    <td width ="80px" align="right">条码或名称: </td>
                    <td width ="110px" ><input class="mini-textbox" id ="SearchKey" width ="110px" name = "SearchKey" onkeypress="setkeyPressGds()"/></td>
                    <td width ="80px" align="center">
                        <a class="mini-button" iconCls="icon-search" onclick="setkeyPressGds" plain="true">查询</a>
                    </td>
                    <td></td>
                </tr>
            </table>       
        </div>
        <div class="mini-fit" >
            <div id="datagrid2" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                    borderStyle="border:1;" url="../Goods/GetSysGoodsList"
                    allowCellSelect="true" allowCellEdit="true" showColumnsMenu="true" fitColumns="false"  
                    sortMode="client" ondrawcell="DrawCell">
                <div property="columns">
                    <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                    <div type="checkboxcolumn"  width="40" field="Flag" trueValue="1" falseValue="0"></div>
                    <div field="FGoodsImg" name="FGoodsImg" width="60" headeralign="center" allowsort="true" style="font-size:12pt !important;">图片</div>                    
                    <div field="FName" name="FName" width="150" headeralign="center" allowsort="true">商品名称</div>
                    <div field="FCode" name="FCode" width="150" headeralign="center" allowsort="true">商品条码</div>                    
                    <div field="FSpec" name="FSpec" width="90" headeralign="center" allowsort="true">规格</div>
                    <div field="FUnitName" name="FUnitName" width="70" headeralign="center" allowsort="true">单位</div>
                    <div field="FConvert" name="FConvert" width="70" headeralign="center" allowsort="true">内装数</div>
                    <div field="FPurPrice" name="FPurPrice" width="70" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">进货价</div>
                    <div field="FPosPrice" name="FPosPrice" width="70" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">零售价</div>
                    <div field="FMallPrice" name="FMallPrice" width="70" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">电商价</div>
                    <div field="FSelPrice" name="FSelPrice" width="70" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">批发价</div>
                    <div field="FVipPrice" name="FVipPrice" width="70" numberFormat="#,0.00" headerAlign="center" align="right" allowSort="true">会员价</div>
                    <div field="FClassName" name="FClassName" width="150" headeralign="center" allowsort="true">商品分类</div>
                </div>
            </div>
        </div>
    </div>
</div>

    <ul id="popupMenu" class="mini-menu" style="display:none;">
        <li id="getLocaData0" iconCls="icon-search" onclick="search(0)">刷新</li>
        <li class="separator"></li>
	    <li id="getLocaData1" iconCls="icon-undo" onclick="search(1)">有图</li>
        <li id="getLocaData2" iconCls="icon-edit" onclick="search(2)">无图</li>
        <li class="separator"></li>
    </ul>

<script>
    function FormShown() {
        mini.parse();
        LoadClassData();
        LoadGoodsData();
    }

    function LoadClassData() {
        var sSystemAppID = parent.window.getSystemAppID();
        var json = "[{";
        json = json + "'mSystemAppID':" + "'" + sSystemAppID + "',";
        json = json + "'search':" + "'" + mini.getbyName("FSearchKey").getValue() + "'";
        json = json + "}]";
        var grid = mini.get("datagrid1");
        grid.load({ json: json });
    }

    function GetSelectRows() {
        var grid1 = mini.get("datagrid1");
        var rows = grid1.getData();
        var FClassStr = '';
        for (var i = 0, l = rows.length; i < l; i++) {
            var row = rows[i]
            if(row.Flag)
                FClassStr = FClassStr + row.FClassName + ',';
        }
        return FClassStr;
    }

    function LoadGoodsData(mDataType) {
        var grid1 = mini.get("datagrid1");
        var rows = grid1.getSelecteds();
        var FClassStr = GetSelectRows();
        var sSystemAppID = parent.window.getSystemAppID();
        var json = "[{";
        json = json + "'mDataType':" + "'" + mDataType + "',";
        json = json + "'FClass':" + "'" + FClassStr + "',";
        json = json + "'mSystemAppID':" + "'" + sSystemAppID + "',";
        json = json + "'search':" + "'" + mini.getbyName("SearchKey").getValue() + "'";
        json = json + "}]";
        var grid = mini.get("datagrid2");
        grid.load({ json: json });
    }
    function search(mDataType) {
        LoadGoodsData(mDataType);
    }
    function setkeyPressCls() {
        LoadClassData();
    }
    function setkeyPressGds() {
        LoadGoodsData();
    }
    function save() {
        var jsonstr = getJson();
        if (jsonstr.length < 10)
        {
            mini.alert("请选择要引入的商品！");
            return;
        }
        $.post("ImportSave", { json: jsonstr, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: '引入成功', state: "success", x: "center", y: "top", timeout: 3000 });
            }
            else {
                mini.showTips({ content: '引入失败 ' + ret.error, state: "danger", x: "center", y: "top", timeout: 3000 });
            }
        });
    }

    function DrawCell(e) {
        if (e.columnIndex == 2) {
            var PicUrl = e.row.FGoodsImg;
            if (PicUrl == '') {
                PicUrl = 'http://ct.posyun3721.com:7006/content/images/PImage.jpg';
            } else {
                PicUrl = 'http://erp.pos08.com/' + PicUrl;
            }
            e.cellHtml = '<img src="' + PicUrl + '" width="50px" height="40px" />';
        }
    }

    function getJson() {
        var grid2 = mini.get("datagrid2");
        var rows = grid2.getData();
        var jsonstr = '';
        for (var i = 0, l = rows.length; i < l; i++) {
            var row = rows[i]
            if (row.Flag) {
                if (jsonstr.length > 0)
                    jsonstr += ',';
                else
                    jsonstr = '[';
                jsonstr += '{"FItemID":"' + row.FItemID + '","FCode":"' + row.FCode + '","FClassName":"' + row.FClassName
                    + '","FName":"' + row.FName + '","FSpec":"' + row.FSpec + '","FConvert":"' + row.FConvert + '","FPriceType":"' + row.FPriceType
                    + '","FUnitName":"' + row.FUnitName + '","FPurPrice":"' + row.FPurPrice + '","FPosPrice":"' + row.FPosPrice
                    + '","FSpelling":"' + row.FSpelling + '","FMakeIn":"' + row.FMakeIn + '","FParentCode":"' + row.FParentCode
                    + '","FProImage":"' + row.FProImage + '","FContent":"' + row.FContent + '"}'
            }
        }
        jsonstr += ']';
        return jsonstr;
    }
</script>